/**
 * 
 */
package com.base.myproject.client.busi.b2c.shopping;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.JDBCModelData;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseImageList;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.user.client.ui.Widget;


/**
 * 订单，从购物车直接下订单到订单模块
 * 每一笔订单都有一个订单号，一个订单下有多个商品，
 * @author zgw
 *2009-8-15 下午09:37:25
 * javazgw@gmail.com
 */
public class ShoppingOrder extends LayoutContainer {
	String ccode = null;
	static BaseStore<BaseModelData> store = null;
	static BaseStore<BaseModelData> storeg  = null;
	static BaseImageList bl = null;
	public ShoppingOrder(String ccode)
	{
		this.ccode = ccode;
		init();
	}
	
	private void init() {
		
		add(CreateListOrderPanel());
		add(CreateListOrderGPanel());
	}

	static Widget CreateListOrder() {

		bl = new BaseImageList(store, null, false) {

			protected native String getTemplate() /*-{
		var r3= ['<form id=\"formshoppingcart\"  action=\"/"+GWT.getModuleName()+"/BaseServlet?action=test1\" method=\"post\"><table class=\"tblCart\"   border=\"0\" width=\"100%\" cellspacing=\"1px\" cellpadding=\"1px\" id=\"cartContentsDisplay\"> ', 

			 '<tr class="tableHeading"> ',
		'<th   scope="col" id="imagepath">商品</th> ',
		'<th   scope="col" id="b2cgname">商品名</th> ',
		'<th   scope="col" id="pric">单价</th> ',
		'<th   scope="col" id="discountpric">折扣单价</th> ',
		'<th   scope="col" id="qty">数量</th> ',
		'<th   scope="col" id="totle">总价</th> ',
	
		'<th   scope="col" id="index">删除</th> ',


		'<tpl  for=".">',
		'<tpl if="xindex %2 ==1">',
		'<tr class="tblEven" id=\"{icode}\">',
		'</tpl>',
		'<tpl if="xindex %2 ==0">',
		'<tr class="tblOdd" id=\"{icode}\">',
		'</tpl>',
		
		'<td width=\"25%\" ><img src =\"{imagepath}\" width=\"100px\"  /></td>',
		'<td width=\"25%\" style=\"text-align:left" >{b2cgname}</td>',
		'<td width=\"10%\">{price}</td>',
		'<td width=\"10%\">{discountpric}</td>',
		'<td width=\"10%\"><input name=\"{icode}ss\" type=\"text\" onKeyUp=\"javascript:setautodisplaytocenter(this.value,{icode})\" /></td>',
		'<td width=\"10%\">{totle}</td>',
	
		'<td width=\"10%\"><a href=\"javascript:void(0);\" onclick=\"javascript:doDeltr(this);\">删除</a></td>',
		'</tpl>',


		'</tr>',

		'</table><hr /><a href=\"javascript:void(0)\"  onclick=\"javascript:shoppingcartsubmit(form123)\" style="background-color:#FF6600; color:#FFFFFF">下订单 </a> ',
		'<a href=\"javascript:void(0)\"  onclick=\"javascript:shoppingcartsubmit(form123)\" style="background-color:#999999; color:#FFFFFF">    继续购物</a>',
	
		'</form>',
		'<div class="x-clear"><hr /></div>'].join(""); 
		return r3;
	}-*/;

		};
		return bl;
	}
	
	
	void CreateImageStoreg() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("icode");
		type.addField("b2cgcode");
		type.addField("b2cgname");
		type.addField("gcode");
		type.addField("gname");
		type.addField("ordercode");
		type.addField("qty");
		type.addField("finalprice");
		type.addField("totle");
		
		type.addField("bcode");
		type.addField("bname");
		
		type.addField("ccode");
		type.addField("cname");

		StoreInfo info = new StoreInfo();

		info.setTablename("b2clistorderg");
		info.setSql("select * from b2clistorderg ");
		info.setParent(store);// 关联主表
		
		info.setLinkparentcolumns(new String[] { "ordercode" }); // 关联主表字段
		 storeg = new BaseStore<BaseModelData>(type, info);
		

	}
	void CreateImageStore() {
		ModelType type = new ModelType();
		type.setRoot("records");
		type.setRecordName("record");
		type.addField("icode");
	
		type.addField("ordercode");
		
		type.addField("totle");
		
		type.addField("orderdate");
		type.addField("status");
		
		type.addField("ccode");
		type.addField("cname");
		type.addField("totalmoney");

		StoreInfo info = new StoreInfo();

		info.setTablename("b2clistorder");
		info.setSql("select * from b2clistorder where ccode = '" + ccode + "'");
		
		store = new BaseStore<BaseModelData>(type, info);
		

	}
	/**
	 * 订单主表
	 * @return
	 */
	@SuppressWarnings("unused")
	private BaseGrid<JDBCModelData> CreateListOrderPanel() {
		
		CreateImageStore();
		CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		columns.add(cbs.getColumn());
		ColumnConfig ordercode = new ColumnConfig("ordercode", "商品编号", 100);
		
		columns.add(ordercode);
		ColumnConfig orderdate = new ColumnConfig("orderdate", "下订单日期", 100);
		columns.add(orderdate);
		ColumnConfig status = new ColumnConfig("status", "订单所处状态", 100);
		columns.add(status);
		ColumnConfig totalmoney = new ColumnConfig("totalmoney", "订单金额", 100);
		columns.add(totalmoney);
		
		
		ColumnModel cm = new ColumnModel(columns);
		BaseGrid<JDBCModelData> listordergrid = new BaseGrid<JDBCModelData>(store, cm,false,false);
		listordergrid.setAutoHeight(true);
		listordergrid.setAutoWidth(true);
		
		cbs.setSelectionMode(SelectionMode.SINGLE);
		listordergrid.setSelectionModel(cbs);
		return listordergrid;
	}
	/**
	 * 订单商品表
	 * @return
	 */
	@SuppressWarnings("unused")
	private BaseGrid<JDBCModelData> CreateListOrderGPanel() {
		
		CreateImageStoreg();
		List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		
		

		ColumnConfig b2cgcode = new ColumnConfig("b2cgcode", "商品编号", 100);
		columns.add(b2cgcode);
		ColumnConfig b2cgname = new ColumnConfig("b2cgname", "商品描述", 100);
		columns.add(b2cgname);
		
		ColumnConfig qty = new ColumnConfig("qty", "下单数量", 100);
		columns.add(qty);
		ColumnConfig finalprice = new ColumnConfig("finalprice", "单价", 100);
		columns.add(finalprice);
		ColumnConfig totle = new ColumnConfig("totle", "总金额", 100);
		columns.add(totle);
	
		
		
		ColumnModel cm = new ColumnModel(columns);
		BaseGrid<JDBCModelData> listorderggrid = new BaseGrid<JDBCModelData>(storeg, cm,false,false);
		listorderggrid.setAutoHeight(true);
		listorderggrid.setAutoWidth(true);
		return listorderggrid;
	}
}
